package com.op.studyingliteapp.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.op.studyingliteapp.R;
import com.op.studyingliteapp.bean.UserBean;
import com.op.studyingliteapp.database.dao.UserDao;
import com.op.studyingliteapp.widget.RoundImageView;
import com.op.util.SharedPreferenceUtil;

public class UserInformationActivity extends Activity {

	public ImageLoader imageLoader = ImageLoader.getInstance();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_user_information);
	//	imageLoader.init(ImageLoaderConfiguration.createDefault(this));
		RoundImageView imageButton = (RoundImageView) findViewById(R.id.user_image);
		// 个人信息显示
		TextView userName = (TextView) findViewById(R.id.user_information_user_name);
		TextView userNumber = (TextView) findViewById(R.id.user_information_number);
		TextView userSex = (TextView) findViewById(R.id.user_information_sex);
		TextView userUniversity = (TextView) findViewById(R.id.user_information_university);
		TextView userType = (TextView) findViewById(R.id.user_information_user_type);
		TextView userReallyName = (TextView) findViewById(R.id.user_information_name);
		// 通过SharedPreference获取userId
		SharedPreferences getUser = SharedPreferenceUtil.getInstance(UserInformationActivity.this);
		UserDao userDao = new UserDao(UserInformationActivity.this);
		UserBean userBean = userDao.getUserByUserId(getUser.getString("userId", "未知"));
		// 读取头像和信息写入
		ImageLoader.getInstance().displayImage(userBean.getImageUrl(), imageButton);
		userName.setText(userBean.getName());
		userNumber.setText(userBean.getNumber());
		userSex.setText("未知");
		userUniversity.setText("未知");
		userType.setText(userBean.getType());
		userReallyName.setText(userBean.getName());
		// 退出用户按钮
		findViewById(R.id.exit_login).setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(UserInformationActivity.this, LoginActivity.class);
				startActivity(intent);
				finish();
			}
		});
	}

	@Override
	public void onResume() {
		super.onResume();

	}
}
